package cn.skyquant.quant4j.jforex.sdk.strategy;

import cn.skyquant.quant4j.sdk.enums.TradeDirection;

import java.util.ArrayList;
import java.util.Formatter;
import java.util.List;

public class OrderExManager {
    public final List<OrderEx> buyLimitList = new ArrayList<>();//所有多单限价挂单
    public final List<OrderEx> buyStopList = new ArrayList<>();//所有多单突破挂单
    public final List<OrderEx> buyList = new ArrayList<>();      //所有成交多单
    public final List<OrderEx> sellLimitList = new ArrayList<>();//所有空单限价挂单
    public final List<OrderEx> sellStopList = new ArrayList<>();//所有空单突破挂单
    public final List<OrderEx> sellList = new ArrayList<>();      //所有成交空单
    public OrderEx buy_first = null;                        //多单首仓
    public OrderEx buy_last = null;                         //多单尾仓
    public OrderEx sell_first = null;                       //空单首仓
    public OrderEx sell_last = null;                        //空单尾仓
    public double buy_pl_usd = 0;                            //多单盈利钱（美元）
    public double buy_pl_pip = 0;                            //多单盈利点
    public double sell_c = 0;                            //空单手续费（美元）
    public double buy_c = 0;                            //多单手续费（美元）
    public double sell_pl_usd = 0;                           //空单盈利钱（美元）
    public double sell_pl_pip = 0;                           //空单盈利点


    public OrderExManager() {
    }

    public double getPLUSD(TradeDirection tradeDirection) {
        return tradeDirection == TradeDirection.LONG ? buy_pl_usd : sell_pl_usd;
    }

    public List<OrderEx> getOrderExList(TradeDirection tradeDirection) {
        return tradeDirection == TradeDirection.LONG ? buyList : sellList;
    }

    public List<OrderEx> getLimitOrderExList(TradeDirection tradeDirection) {
        return tradeDirection == TradeDirection.LONG ? buyLimitList : sellLimitList;
    }

    public List<OrderEx> getStopOrderExList(TradeDirection tradeDirection) {
        return tradeDirection == TradeDirection.LONG ? buyStopList : sellStopList;
    }

    public List<OrderEx> getReflectOrderExList(TradeDirection tradeDirection) {
        return tradeDirection == TradeDirection.LONG ? sellLimitList : buyLimitList;
    }

    public OrderEx getReflectLastOrderEx(TradeDirection tradeDirection) {
        return tradeDirection == TradeDirection.LONG ? sell_last : buy_last;
    }

    public OrderEx getFirst(TradeDirection tradeDirection) {
        return tradeDirection == TradeDirection.LONG ? buy_first : sell_first;
    }

    public OrderEx getLast(TradeDirection tradeDirection) {
        return tradeDirection == TradeDirection.LONG ? buy_last : sell_last;
    }

    @Override
    public String toString() {
        Formatter formatter = new Formatter();
        formatter.format("buyList=%d,buyLimitList=%d,buyStopList=%d,sellList=%d,sellLimitList=%d,sellStopList=%d",
                buyList.size(), buyLimitList.size(), buyStopList.size(),
                sellList.size(), sellLimitList.size(), sellStopList.size());
        return formatter.toString();
    }
}
